package cn.hhit.ximalaya.adapters;

import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.squareup.picasso.Picasso;
import com.ximalaya.ting.android.opensdk.constants.DTransferConstants;
import com.ximalaya.ting.android.opensdk.datatrasfer.CommonRequest;
import com.ximalaya.ting.android.opensdk.datatrasfer.IDataCallBack;
import com.ximalaya.ting.android.opensdk.model.album.Album;
import com.ximalaya.ting.android.opensdk.model.album.GussLikeAlbumList;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.hhit.ximalaya.R;
import cn.hhit.ximalaya.utils.Constants;
import cn.hhit.ximalaya.utils.LogUtil;

public class AlbumListAdapter  extends RecyclerView.Adapter<AlbumListAdapter.InnerHolder>{
    public final   String TAG=" AlbumListAdapter";

    private List<Album> mData = new ArrayList<>();
    /**
     * 功能：导入外部数据
     */

    public void setData(List<Album> albumList) {
        if (mData != null) {
            mData.clear();
            mData.addAll(albumList);
            LogUtil.d(TAG,"1:mData数量"+mData.size());
        }
        //更新一下UI。
        notifyDataSetChanged();
    }
    @NonNull
    @Override
    public AlbumListAdapter.InnerHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View item= LayoutInflater.from(parent.getContext()).inflate(R.layout.item_recommend, parent, false);
        InnerHolder innerHolder=new InnerHolder(item);
        return innerHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull AlbumListAdapter.InnerHolder holder, int position) {
        //给每个item设置一个标记
        holder.itemView.setTag(position);


        holder.setData(mData.get(position));



    }

    @Override
    public int getItemCount() {
        return mData==null?0: mData.size();
    }
    class InnerHolder extends RecyclerView.ViewHolder {

        public InnerHolder(@NonNull View itemView) {
            super(itemView);
        }

        public void setData(Album album) {
            //找到各个控件，设置数据
            //专辑封面
            ImageView albumCoverIv = itemView.findViewById(R.id.album_cover);
            //title
            TextView albumTitleTv = itemView.findViewById(R.id.album_title_tv);
            //描述
            TextView albumDesTv = itemView.findViewById(R.id.album_description_tv);
            //播放数量
            TextView albumPlayCountTv = itemView.findViewById(R.id.album_play_count);
            //专辑内容数量
            TextView albumContentCountTv = itemView.findViewById(R.id.album_content_size);
            //文字
            albumTitleTv.setText(album.getAlbumTitle());
            albumDesTv.setText(album.getAlbumIntro());
            albumPlayCountTv.setText(album.getPlayCount() + "");
            albumContentCountTv.setText(album.getIncludeTrackCount() + "");

            //图片
            Picasso.with(itemView.getContext())
                    .load(album.getCoverUrlLarge())
                    .into(albumCoverIv);


        }
    }


}
